local blaze = require "blaze"
local app = require "app"
local Room = require "entities.Room"
local game = app.game.running

local M = game.kbe.entity("BaccaratRoom", Room)

function M:__init()
    Room.__init(self)
end

local phase2name = 
{
    [0] = "idle 等待下注",
    [1] = "bet 开始下注",
    [2] = "reveal 停止下注，展示结果",
    [3] = "settle 结算 动画",
    [4] = "payout 派彩 动画",
}

function M:set_bet_amounts(old)
    self.log.debug("set_bet_amounts")
    game.store.bet_amounts.setup(self.bet_amounts)
end

function M:on_phase(phase_id, countdown)
    game.store.gameplay.set_phase({phase_id = phase_id, countdown = countdown})
    self.log.debug(string.format("当前阶段：%s 倒计时：%s", phase2name[phase_id], countdown))
end

-- @view:{banker = {1, 2, 3}, player = {1, 2, 3}, hits = [1, 2, 3], payout_detail = [{id:1, payout:100}]}
function M:on_reveal(view, payout_detail)
    self.log.debug(string.format("收到游戏结果:%s payout_detail:%s", blaze.dump(view), blaze.dump(payout_detail)))
    game.store.gameplay.reveal({view = view, payout_detail = payout_detail})
end

-- @views [view, view, veiw]
function M:on_sync_record(views)
    self.log.debug('同步游戏 记录')
    game.store.gameplay.sync_record(views)
end

return M